package school.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import school.domain.Comment;
import school.mapper.CommentMapper;
import school.support.BaseController;

import java.util.Date;

@RequestMapping("comment")
@Controller
public class CommentController extends BaseController {

    @Autowired
    private CommentMapper commentMapper;

    /**
     * 评论
     *
     * @return
     */
    @RequestMapping("send")
    public String send(String content, Integer goodsid) {
        if (null == sessionUser()) {
            session.setAttribute("errorMsg", "请先登录");
            return "redirect:/index";
        }
        session.removeAttribute("errorMsg");
        Comment comment = new Comment();
        comment.setAddtime(new Date());
        comment.setContent(content);
        comment.setGoodsid(goodsid);
        comment.setUserid(frontUser().getId());
        commentMapper.insertSelective(comment);
        session.setAttribute("errorMsg", "评论成功");
        return refresh();
    }
}
